package survivial;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import knoxcraft.KnoxWorld;
import tutorial.BlockTutorialBlock;
import tutorial.ItemTutorial;
import tutorial.ItemTutorialBlock;
import tutorial.Tutorial;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFurnace;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntitySignRenderer;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntitySign;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.modloader.BaseModTicker;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;

@Mod(modid = Survivial.modid, name = "Survivial Mod", version = "0.0")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Survivial
{
	public static final String modid = "survivial";

	static public BlockCampfire campfireIdle;
	static public BlockCampfire campfireBright;
	static public BlockCampfire campfireBrightLow;
	static public BlockCampfire campfireMedium;
	static public BlockCampfire campfireMediumLow;
	static public BlockCampfire campfireDim;
	static public BlockCampfire campfireDimLow;
	static public Item ash;
	static public Block smoke;

	// public static final Block furnaceIdle = (new BlockFurnace(61,
	// false)).setHardness(3.5F).setStepSound(soundStoneFootstep).setUnlocalizedName("furnace").setCreativeTab(CreativeTabs.tabDecorations);
	// public static final Block furnaceBurning = (new BlockFurnace(62,
	// true)).setHardness(3.5F).setStepSound(soundStoneFootstep).setLightValue(0.875F).setUnlocalizedName("furnace");
	
	static public Minecraft TheMineCraft;
	static public WorldClient getWorld()
	{
		if (_world != TheMineCraft.theWorld)
		{
			_world = TheMineCraft.theWorld;

			_world.getPlayerEntityByName("name");
	    	List players = _world.playerEntities;
	    	
	    	for(int i = 0; i < players.size(); i++)
	    	{
	    		EntityPlayer p = (EntityPlayer)players.get(i);
	    		Player = p;
	    	}
		}
		return _world;
	}
	static private WorldClient _world;
	
	static public EntityPlayer Player;
	
	static public SurvivialTickHandler Ticker;
	
	static public long SystemTime;
	

	@EventHandler
	public void load(FMLInitializationEvent event)
	{
		TheMineCraft = Minecraft.getMinecraft();
		
		SystemTime = TheMineCraft.getSystemTime();
		
		smoke = new BlockSmoke(607);
		smoke.setUnlocalizedName("Smoke");
		
		campfireIdle = new BlockCampfire(600, false);
		campfireIdle.setUnlocalizedName("Campfire");
		campfireIdle.setCreativeTab(CreativeTabs.tabDecorations);

		campfireBright = new BlockCampfire(601, true);
		campfireBright.setUnlocalizedName("Campfire");
		campfireBright.setLightValue(1F);
		
		campfireBrightLow = new BlockCampfire(602, true);
		campfireBrightLow.setUnlocalizedName("Campfire");
		campfireBrightLow.setLightValue(0.93F);


		campfireMedium = new BlockCampfire(603, true);
		campfireMedium.setUnlocalizedName("Campfire");
		campfireMedium.setLightValue(0.85F);
		
		campfireMediumLow = new BlockCampfire(604, true);
		campfireMediumLow.setUnlocalizedName("Campfire");
		campfireMediumLow.setLightValue(0.77F);

		campfireDim = new BlockCampfire(605, true);
		campfireDim.setUnlocalizedName("Campfire");
		campfireDim.setLightValue(0.7F);
		
		campfireDimLow = new BlockCampfire(606, true);
		campfireDimLow.setUnlocalizedName("Campfire");
		campfireDimLow.setLightValue(0.63F);

		GameRegistry.registerBlock(campfireIdle, ItemCampfireBlock.class, modid + (campfireIdle.getUnlocalizedName().substring(5)));
		LanguageRegistry.addName(new ItemStack(campfireIdle, 1, 0), "Campfire Block");

		ash = new ItemAsh(6000).setUnlocalizedName("ash");
		LanguageRegistry.addName(ash, "Ash Item");

		// GameRegistry.registerBlock(campfireLit, ItemCampfireLitBlock.class,
		// modid + (campfireLit.getUnlocalizedName().substring(5)));
		// LanguageRegistry.addName(new ItemStack(campfireLit, 1, 0),
		// "Campfire Lit Block");

		// campfireItem = new ItemCampfire(5000);
		// campfireItem.setUnlocalizedName("Campfire");
		// LanguageRegistry.addName(campfireItem, "Campfire Item");

		GameRegistry.addRecipe(new ItemStack(Survivial.campfireIdle), new Object[]
			{ " S ", "RWR", 'S', Item.stick, 'R', Block.cobblestone, 'W', Block.wood });

		KnoxWorld.RemoveRecipe(Block.furnaceIdle.blockID);

		// FurnaceRecipes.smelting().addSmelting(1, par2ItemStack, par3);

		Map sl = FurnaceRecipes.smelting().getSmeltingList();
		sl.remove(Block.wood.blockID);

		FurnaceRecipes.smelting().addSmelting(Block.wood.blockID, new ItemStack(ash, 1, 1), 0.15F);

        Ticker = new SurvivialTickHandler();
        TickRegistry.registerTickHandler(Ticker, Side.CLIENT);

		/*
		 * Set keys = sl.keySet(); for(Iterator<Object> i = keys.iterator();
		 * i.hasNext(); ) { int id = (Integer) i.next();
		 * 
		 * if (id == Block.wood.blockID) { }
		 * 
		 * 
		 * }
		 */
        
        SurvivialRenderGlobal srg = new SurvivialRenderGlobal(TheMineCraft);
        TheMineCraft.renderGlobal = srg;

		// GameRegistry.registerTileEntity(TileEntityCampfire.class,
		// "Campfire");
		// TileEntityRenderer.instance.specialRendererMap.put(TileEntityCampfire.class,
		// new TileEntityCampfireRenderer());
	}

}